﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace CarsTitans
{
    public class Entity
    {
        public Model ModelCar = null;
        public float MaxRadius = float.MinValue;
        public Matrix Transform
        {
            get { return ModelCar.Root.Transform; }
            set { ModelCar.Root.Transform = value; }
        }
        public Entity(string asset, ContentManager content )
        {
            ModelCar = content.Load<Model>(asset);
            MaxRadius = float.MinValue;
            foreach (ModelMesh mesh in ModelCar.Meshes)
            {
                if (mesh.BoundingSphere.Radius > MaxRadius)
                {
                    MaxRadius = mesh.BoundingSphere.Radius;
                }
            }
            foreach (ModelMesh mesh in ModelCar.Meshes)
            {
                foreach (BasicEffect ef in mesh.Effects)
                {
                    foreach (EffectParameter p in ef.Parameters)
                    {
                        System.Diagnostics.Debug.WriteLine(p.Name);
                    }
                }
            }
            System.Diagnostics.Debug.WriteLine("MaxRadius=" + MaxRadius);
        }
        public virtual void Render(Matrix view, Matrix projection)
        {
            Render(Transform, view, projection);
        }
        public virtual void Render(Matrix world, Matrix view, Matrix projection)
        {
            ModelCar.Root.Transform = world;
            foreach (ModelMesh mesh in ModelCar.Meshes)
            {
                foreach (BasicEffect ef in mesh.Effects)
                {
                    ef.World = world;
                    ef.View = view;
                    ef.Projection = projection;
                    ef.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
        public virtual void Update(GameTime time)
        {
            
        }
    }
}
